package cn.iocoder.yudao.module.myerp.controller.admin.SKCproduct;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.myerp.controller.admin.SKCproduct.vo.*;
import cn.iocoder.yudao.module.myerp.dal.dataobject.SKCproduct.ErpProductSkcDO;
import cn.iocoder.yudao.module.myerp.service.SKCproduct.ErpProductSkcService;

@Tag(name = "管理后台 - ERP SKC级产品")
@RestController
@RequestMapping("/myerp/erp-product-skc")
@Validated
public class ErpProductSkcController {

    @Resource
    private ErpProductSkcService erpProductSkcService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP SKC级产品")
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:create')")
    public CommonResult<Long> createErpProductSkc(@Valid @RequestBody ErpProductSkcSaveReqVO createReqVO) {
        return success(erpProductSkcService.createErpProductSkc(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP SKC级产品")
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:update')")
    public CommonResult<Boolean> updateErpProductSkc(@Valid @RequestBody ErpProductSkcSaveReqVO updateReqVO) {
        erpProductSkcService.updateErpProductSkc(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP SKC级产品")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:delete')")
    public CommonResult<Boolean> deleteErpProductSkc(@RequestParam("id") Long id) {
        erpProductSkcService.deleteErpProductSkc(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP SKC级产品")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:query')")
    public CommonResult<ErpProductSkcRespVO> getErpProductSkc(@RequestParam("id") Long id) {
        ErpProductSkcDO erpProductSkc = erpProductSkcService.getErpProductSkc(id);
        return success(BeanUtils.toBean(erpProductSkc, ErpProductSkcRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP SKC级产品分页")
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:query')")
    public CommonResult<PageResult<ErpProductSkcRespVO>> getErpProductSkcPage(@Valid ErpProductSkcPageReqVO pageReqVO) {
        PageResult<ErpProductSkcDO> pageResult = erpProductSkcService.getErpProductSkcPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ErpProductSkcRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP SKC级产品 Excel")
    @PreAuthorize("@ss.hasPermission('myerp:erp-product-skc:export')")
    @OperateLog(type = EXPORT)
    public void exportErpProductSkcExcel(@Valid ErpProductSkcPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<ErpProductSkcDO> list = erpProductSkcService.getErpProductSkcPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP SKC级产品.xls", "数据", ErpProductSkcRespVO.class,
                        BeanUtils.toBean(list, ErpProductSkcRespVO.class));
    }

}